package com.DBUtil;

import java.sql.*;

/**
 * @author 20x
 * @date 2024 - 11 -19
 **/
public class DBUtil {
    private static final String URL = "jdbc:sqlserver://localhost:1433;database=goods;Encrypt=true;trustServerCertificate=true";
    private static final String DRIVER ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
    private static final String USER = "sa";
    private static final String PASS = "root";

    static {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public static Connection getConnection(){
        try {
            return DriverManager.getConnection(URL,USER,PASS);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public static void close(ResultSet rst, Statement stmt, Connection conn){
        if(rst != null){
            try {
                rst.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        if(stmt != null){
            try {
                stmt.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        if(conn !=null){
            try {
                conn.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }
    public static void main(String[] args) {
        System.out.println(getConnection());
    }

}
